
#include "rts.h"
#include "scripting.h"

using namespace WtfRts;
using namespace WtfEngine;
using namespace boost::python;


/**** Wrapper Classes ****/

class WeaponWrapper : public Weapon {
public:
	WeaponWrapper(const Weapon::tCreationOptions& opts, const WtfGraphics::GraphicsData::tRef& rGfx, const tPosition& vPos):
	Weapon(opts, rGfx, vPos) {
	};

	bool AttackUnit(const WtfEngine::IRtsUnit::tRef& rMyUnit, const WtfEngine::IRtsUnit::tRef& rUnit) {
		return false;
	};

	GC_AUTOSIZE(WeaponWrapper);
};


/**
 * Exports the WtfRts namespace.
 **/
BOOST_PYTHON_MODULE(WtfRts)
{
	/**** Weapon Base Class ****/

	class_<WeaponWrapper, WeaponWrapper::tRef, bases<GameObject>(), boost::noncopyable>("Weapon",
		init<const Weapon::tCreationOptions&, const WtfGraphics::GraphicsData::tRef&, const tPosition&>())
	;
	implicitly_convertible<WeaponWrapper::tRef, Weapon::tRef>();


	/**** Unit Selection ****/

	class_<WtfEngine::IRtsUnit, WtfEngine::IRtsUnit::tRef, boost::noncopyable>("IRtsUnit", no_init)
		
	;
	class_<UnitSelection::tObjectList >("UnitSelectionList")
		.def(set_indexing_suite<UnitSelection::tObjectList>())
	;
	class_<WtfEngine::ObjectSelection<WtfEngine::IRtsUnit>, WtfEngine::ObjectSelection<WtfEngine::IRtsUnit>::tRef >("UnitSelectionBase", init<>())
	;
	class_<UnitSelection, UnitSelection::tRef, bases<WtfEngine::ObjectSelection<WtfEngine::IRtsUnit> > >("UnitSelection", init<>())
		.def("Select", &UnitSelection::Select)
		.def("Clear", &UnitSelection::Clear)
		.def("Init", &UnitSelection::Init)
		.def("Destroy", &UnitSelection::Destroy)
		.add_property("selection", make_function(&UnitSelection::getSelection, return_value_policy<reference_existing_object>()))
		.add_property("onChange", make_function(&UnitSelection::getOnChange, return_value_policy<copy_const_reference>()), &UnitSelection::setOnChange)
	;
	implicitly_convertible<UnitSelection::tRef, WtfEngine::ObjectSelection<WtfEngine::IRtsUnit>::tRef >();


	/**** Unit Base Class ****/

	class_<WtfRts::Unit, WtfRts::Unit::tRef, bases<WtfEngine::IRtsUnit>, boost::noncopyable>("Unit", no_init)
		.add_property("health", &Unit::getHealth, &Unit::setHealth)
		.add_property("maxHealth", &Unit::getHealth, &Unit::setHealth)
		.add_property("guardRadius", &Unit::getGuardRadius, &Unit::setGuardRadius)
		.def("AddWeapon", &Unit::AddWeapon)
	;

	/**** Vehicle Base Class ****/

	class_<WtfRts::Vehicle::RtsVehicleCreationOptions
		//, bases<WtfEngine::Vehicle::tCreationOptions>
			>("VehicleCreationOptions")
		.def_readwrite("numAxles", &WtfRts::Vehicle::RtsVehicleCreationOptions::iNumAxles)
		.def_readwrite("wheelRadius", &WtfRts::Vehicle::RtsVehicleCreationOptions::fWheelRadius)
		.def_readwrite("axleSpacing", &WtfRts::Vehicle::RtsVehicleCreationOptions::fAxleSpacing)
		.def_readwrite("axleLength", &WtfRts::Vehicle::RtsVehicleCreationOptions::fAxleLength)
		.def_readwrite("suspensionLength", &WtfRts::Vehicle::RtsVehicleCreationOptions::fSuspensionLength)
		.def_readwrite("frontAxlePosition", &WtfRts::Vehicle::RtsVehicleCreationOptions::vFrontAxlePosition)
		.def_readwrite("physicalDimensions", &WtfRts::Vehicle::RtsVehicleCreationOptions::vPhysicalDimensions)
		.def_readwrite("centreOfMass", &WtfRts::Vehicle::RtsVehicleCreationOptions::vCentreOfMass)
		.def_readwrite("mass", &WtfRts::Vehicle::RtsVehicleCreationOptions::fMass)
	;

	class_<WtfRts::Vehicle, WtfRts::Vehicle::tRef, bases<Unit>, boost::noncopyable>("Vehicle",
		init<const WtfRts::Vehicle::tCreationOptions&, const WtfGraphics::GraphicsData::tCacheRef&>())
		.add_property("goalPosition", &WtfRts::Vehicle::getGoalPosition)
		.add_property("goalRadius", &WtfRts::Vehicle::getGoalRadius)
	;

	/**** Structure Base Class ****/

};

void WtfRts::ExportToPython() {
	initWtfRts();
};
